﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Data.SqlClient;
using System.IO;

using DataAccessEntLib;
using System.Text;

public partial class Search : System.Web.UI.Page
{
    BO.Ad bo = new BO.Ad();
    BLL.AdMagnager bll = new BLL.AdMagnager(); 
    public string TotalAds = string.Empty;

    protected void Page_Load(object sender, EventArgs e)
    {
        adList1.RequestDataSet += new Classified_UserControls_Cld_List.ReBindDataSet(UC_RequestDataSet);
        if (!IsPostBack)
        {
            adList1.dsAds= AdvancedSearch();

        }
        Label lblEmpty = adList1.FindControl("lblEmptyMessage") as Label;
        lblEmpty.Text = "Sorry no Ads found. Try searching with some other Criteria";
    }


    DataSet UC_RequestDataSet(object sender)
    {
        return AdvancedSearch();
    }
    protected DataSet AdvancedSearch()
    {
        StringBuilder sbSearchFor = new StringBuilder();
        sbSearchFor.Append("Showing Results for ");
        if (Session["AdTitle"] != null)
        {
            bo.AdTitle = Session["AdTitle"].ToString();
            sbSearchFor.Append("'"+bo.AdTitle+"'");
        } 
        if (Session["CategoryID"] != null)
        {
            bo.CategoryID = Convert.ToInt32(Session["CategoryID"]);
            if (!string.IsNullOrEmpty( bo.AdTitle))
                sbSearchFor.Append(" in ");
            sbSearchFor.Append("'" + Convert.ToString(Session["CategoryName"]) + "'");
        }
        if (Session["SubCategoryID"] != null)
        {
            bo.SubCategoryID = Convert.ToInt32(Session["SubCategoryID"]);
            if (!string.IsNullOrEmpty(bo.AdTitle)  || bo.CategoryID > 0)
                sbSearchFor.Append(" in ");
            sbSearchFor.Append("'" + Convert.ToString(Session["SubCategoryName"]) + "'");
        }
      
        if (Session["SearchValue"] != null)
        {
            bo.SearchValue = Session["SearchValue"].ToString();
            bo.ColumnName = Session["SearchValue"].ToString();
        }
        if(sbSearchFor.Length>0)
        lblSearchTitle.Text = sbSearchFor.ToString();
        return bll.SelectAdvancedSearch(bo);
    }
}